package com.movie.modules.jf.controller;

import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.movie.modules.jf.entity.TypeEntity;
import com.movie.modules.jf.service.TypeService;
import com.movie.common.utils.PageUtils;
import com.movie.common.utils.R;



/**
 * 类型表
 *
 * @author kakarot
 * @email 532050892@qq.com
 * @date 2021-08-20 01:31:11
 */
@RestController
@RequestMapping("/sys/type")
@Api(tags = "后台类型模块")
public class TypeController {
    @Autowired
    private TypeService typeService;

    /**
     * 列表
     */
    @GetMapping("/movie/list")
    @ApiOperation("电影类型分页")
    public R movieList(@RequestParam Map<String, Object> params){
        params.put("type",1);
        PageUtils page = typeService.queryPage(params);
        return R.ok().put("data", page);
    }

    @GetMapping("/news/list")
    @ApiOperation("新闻类型分页")
    public R newsList(@RequestParam Map<String, Object> params){
        params.put("type",2);
        PageUtils page = typeService.queryPage(params);
        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{typeId}")
    @ApiOperation("电影/新闻类型详情")
    public R info(@PathVariable("typeId") Integer typeId){
		TypeEntity type = typeService.getById(typeId);
        return R.ok().put("data", type);
    }

    /**
     * 保存
     */
    @PostMapping("/movie/update")
    @ApiOperation("添加/修改电影类型")
    public R updateMovieType(@RequestBody TypeEntity type){
        type.setType(1);
        typeService.saveOrUpdate(type);
        return R.ok();
    }

    @PostMapping("/news/update")
    @ApiOperation("添加/修改新闻类型")
    public R updateNewsType(@RequestBody TypeEntity type){
        type.setType(2);
        typeService.saveOrUpdate(type);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/movie/delete/{typeId}")
    @ApiOperation("删除电影类型")
    public R deleteMovieType(@PathVariable("typeId") Integer typeId){
        return typeService.delete(typeId,1);
    }

    @DeleteMapping("/news/delete/{typeId}")
    @ApiOperation("删除新闻类型")
    public R deleteNewsType(@PathVariable("typeId") Integer typeId){
        return typeService.delete(typeId,3);
    }


    @GetMapping("/movie/select")
    @ApiOperation("电影类型下拉框")
    public R movieSelect(){
        return R.ok().put("data",typeService.getSelect(1));
    }

    @GetMapping("/news/select")
    @ApiOperation("新闻类型下拉框")
    public R newsSelect(){
        return R.ok().put("data",typeService.getSelect(2));
    }
}
